package video.web;

import java.util.Calendar;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
 * url example http://my.tv.sohu.com/u/vw/19077427
 * @author ladjzero
 *
 */
public class Sohu extends SuperParser{


	public Sohu(String videoUrl) {
		super(videoUrl);
	}
	
	public String getImage() {
		Pattern pattern = Pattern.compile(",bCover: '(.+?)'");
		Matcher matcher = pattern.matcher("");
		if(null!=content)
			matcher = pattern.matcher(content);
		while(matcher.find())
			return matcher.group(1);
		return null;
	}

	public String getSwf(){
		Calendar calendar = Calendar.getInstance( TimeZone.getDefault());
		String year = String.valueOf( calendar.get(Calendar.YEAR) );
		String month = null;
		if( (calendar.get(Calendar.MONTH)+1)>=10 )
			month = String.valueOf( calendar.get(Calendar.MONTH)+1 );
		else
			month = "0"+( calendar.get(Calendar.MONTH)+1 );
		String day = null;
		if( calendar.get(Calendar.DAY_OF_MONTH)>=10 )
			day = String.valueOf(calendar.get(Calendar.DAY_OF_MONTH));
		else
			day = "0"+calendar.get(Calendar.DAY_OF_MONTH);
		return "http://tv.sohu.com/upload/swf/"+year+month+day+"/PlayerShell.swf?autoplay=false&skinNum=1&id="+getIdFromVideoUrl( videoUrl );
	}
	
	private String getIdFromVideoUrl(String videoUrl){
		return videoUrl.substring( videoUrl.lastIndexOf("/")+1 );
	}
}
